home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / SPIM Folder / Sources / inst.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-23  |  5.3 KB  |  173 lines  |  [TEXT/ttxt]

  1. /* SPIM S20 MIPS simulator.
  2.    Description of a SPIM S20 instruction.
  3.    (Layout does not correspond to MIPS machine.)
  4.    Copyright (C) 1990 by James Larus (larus@cs.wisc.edu).
  5.  
  6.    SPIM is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by the
  8.    Free Software Foundation; either version 1, or (at your option) any
  9.    later version.
  10.  
  11.    SPIM is distributed in the hope that it will be useful, but WITHOUT
  12.    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14.    for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GNU CC; see the file COPYING.  If not, write to James R.
  18.    Larus, Computer Sciences Department, University of Wisconsin--Madison,
  19.    1210 West Dayton Street, Madison, WI 53706, USA or to the Free
  20.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. /* Describes an expression that produce a value for an instruction's
  23.    immediate field.  Immediates have the form: label +/- offset. */
  24.  
  25. /* $Header: /var/home/cs354/.spim/RCS/inst.h,v 1.2 1992/10/07 04:07:32 cs354 Exp $ */
  26.  
  27. typedef struct immexpr
  28. {
  29.   long offset;            /* Offset from symbol */
  30.   struct lab *symbol;        /* Symbolic label */
  31.   short bits;            /* > 0 => 31..16, < 0 => 15..0 */
  32.   short pc_relative;        /* Non-zero => offset from label in code */
  33. } imm_expr;
  34.  
  35.  
  36. /* Describes an expression that produce an address for an instruction.
  37.    Address have the form: label +/- offset (register). */
  38.  
  39. typedef struct addrexpr
  40. {
  41.   unsigned char reg_no;        /* Register number */
  42.   imm_expr *imm;        /* The immediate part */
  43. } addr_expr;
  44.  
  45.  
  46.  
  47. /* Choose bland names for fields and #define the real names below.
  48.    This is better than a union since it doesn't require an additional
  49.    level of syntactic indirection in references. */
  50.  
  51. typedef struct inst_s
  52. {
  53.   short opcode;
  54.   unsigned char f1;
  55.   unsigned char f2;
  56.   unsigned char f3;
  57.   unsigned char f4;
  58.   long f5;
  59.   short f5x;
  60.   imm_expr *f6;
  61.   char *comment;
  62. } instruction;
  63.  
  64.  
  65. #define OPCODE(INST)    (INST)->opcode
  66.  
  67. #define RS(INST)    (INST)->f1
  68. #define FS(INST)    (INST)->f1
  69. #define BASE(INST)    (INST)->f1
  70.  
  71. #define RT(INST)    (INST)->f2
  72. #define FT(INST)    (INST)->f2
  73.  
  74. #define RD(INST)    (INST)->f3
  75. #define FD(INST)    (INST)->f3
  76.  
  77. #define SHAMT(INST)    (INST)->f4
  78. #define FORMAT(INST)    (INST)->f4
  79.  
  80. #define IMM(INST)    (INST)->f5x
  81. #define IOFFSET(INST)    (INST)->f5x
  82. #define COND(INST)    (INST)->f5x
  83.  
  84. #define TARGET(INST)    (INST)->f5
  85.  
  86. #define EXPR(INST)    (INST)->f6
  87.  
  88. #define COMMENT(INST)    ((INST)->comment)
  89.  
  90.  
  91. #define COND_UN        0x1
  92. #define COND_EQ        0x2
  93. #define COND_LT        0x4
  94. #define COND_IN        0x8
  95.  
  96.  
  97.  
  98. /* Raise an exception! */
  99.  
  100. #define RAISE_EXCEPTION(CAUSE, MISC)                    \
  101.     {                                \
  102.       if (((CAUSE)<= LAST_REAL_EXCEPT) || (Status_Reg & 0x1))    \
  103.         {                                \
  104.           Cause = (CAUSE) << 2;                    \
  105.           exception_occurred = 1;                    \
  106.           EPC = PC;                            \
  107.           Status_Reg = Status_Reg & 0xffffffc0 | (Status_Reg & 0xf) << 2; \
  108.           MISC;                            \
  109.         }                                \
  110.     }                                \
  111.  
  112. /* Recognized exceptions (see Ch. 5): */
  113.  
  114. #define INT_EXCPT 0
  115. #define ADDRL_EXCPT 4
  116. #define ADDRS_EXCPT 5
  117. #define IBUS_EXCPT 6
  118. #define DBUS_EXCPT 7
  119. #define SYSCALL_EXCPT 8
  120. #define BKPT_EXCPT 9
  121. #define RI_EXCPT 10
  122. #define OVF_EXCPT 12
  123.  
  124.  
  125. /* Floating point exceptions (Ch. 8): */
  126.  
  127. #define INEXACT_EXCEPT 13
  128. #define INVALID_EXCEPT 14
  129. #define DIV0_EXCEPT 15
  130. #define FOVF_EXCEPT 16
  131. #define FUNF_EXCEPT 17
  132.  
  133. #define LAST_REAL_EXCEPT FUNF_EXCEPT
  134.  
  135.  
  136. /* External interrupts: */
  137.  
  138. #define CLOCK_EXCPT 0x100       /* IP[0] */
  139. #define IO_EXCPT 0x200          /* IP[1] */
  140.  
  141. extern    void text_begins_at_point(unsigned long addr);
  142. extern    void k_text_begins_at_point(unsigned long addr);
  143. extern    unsigned long current_text_pc(void);
  144. extern    void increment_text_pc(int delta);
  145. extern    void user_kernel_text_segment(int to_kernel);
  146. extern    void store_instruction(instruction *inst);
  147. extern    void i_type_inst(int opcode,int rt,int rs,struct immexpr *expr);
  148. extern    void j_type_inst(int opcode,struct immexpr *target);
  149. extern    instruction *r_type_inst(int opcode,int rd,int rs,int rt);
  150. extern    void r_sh_type_inst(int opcode,int rd,int rt,int shamt);
  151. extern    void r_cond_type_inst(int opcode,int rs,int rt);
  152. extern    void print_inst(unsigned long addr);
  153. extern    int print_inst_internal(char *buf,instruction *inst,unsigned long addr);
  154. extern    int opcode_is_branch(int opcode);
  155. extern    int opcode_is_jump(int opcode);
  156. extern    int opcode_is_load_store(int opcode);
  157. extern    int inst_is_breakpoint(unsigned long addr);
  158. extern    instruction *set_breakpoint(unsigned long addr);
  159. extern    struct immexpr *make_imm_expr(int offs,char *sym,int pc_rel);
  160. extern    struct immexpr *copy_imm_expr(struct immexpr *old_expr);
  161. extern    struct immexpr *upper_bits_of_expr(struct immexpr *old_expr);
  162. extern    struct immexpr *lower_bits_of_expr(struct immexpr *old_expr);
  163. extern    struct immexpr *const_imm_expr(long value);
  164. extern    struct immexpr *incr_expr_offset(struct immexpr *expr,long value);
  165. extern    long eval_imm_expr(struct immexpr *expr);
  166. extern    int zero_imm(struct immexpr *expr);
  167. extern    addr_expr *make_addr_expr(long offs,char *sym,int reg_no);
  168. extern    struct immexpr *addr_expr_imm(addr_expr *expr);
  169. extern    int addr_expr_reg(addr_expr *expr);
  170. extern    long inst_encode(instruction *inst);
  171. extern    instruction *inst_decode(long value);
  172. extern    void test_assembly(instruction *inst);
  173.